Add gpio_init_mask64 function#2907
Open
FLyrfors-MI wants to merge 6 commits intoraspberrypi:developfrom
Open
Conversation
lurch
reviewed
Apr 23, 2026
lurch
reviewed
Apr 23, 2026
lurch
reviewed
Apr 23, 2026
Co-authored-by: Andrew Scheller <lurch@durge.org>
Early out on no remaining bits in mask for no code cost vs the MIN() version Also optimize the 64 bit methods for NUM_BANK0_GPIOS <= 32
lurch
reviewed
May 9, 2026
Comment on lines
316
to
324
| void gpio_set_function_masked(uint32_t gpio_mask, gpio_function_t fn) { | ||
| for (uint i = 0; i < MIN(NUM_BANK0_GPIOS, 32u); i++) { | ||
| for (uint i = 0; i < NUM_BANK0_GPIOS; i++) { | ||
| if (gpio_mask & 1u) { | ||
| gpio_set_function(i, fn); | ||
| } | ||
| gpio_mask >>= 1; | ||
| if (!gpio_mask) break; | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
It's only a small optimisation, but is it worth doing:
void gpio_set_function_masked(uint32_t gpio_mask, gpio_function_t fn) {
if (gpio_mask) {
for (uint i = 0; i < NUM_BANK0_GPIOS; i++) {
if (gpio_mask & 1u) {
gpio_set_function(i, fn);
}
gpio_mask >>= 1;
if (!gpio_mask) break;
}
}
}(or is it better to assume that this function will never be called with an empty gpio_mask?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
gpio_init_mask64function mirroring the othermask64/masked64GPIO functions used by RP2350B with more than 32 GPIO's.See #2643